# Contributor: Matthias Ahouansou <matthias@ahouansou.cz>
# Contributor: fossdd <fossdd@pwned.life>
# Maintainer: Matthias Ahouansou <matthias@ahouansou.cz>
pkgname=mautrix-gmessages
pkgver=0.5.1
pkgrel=0
pkgdesc="Matrix-Google Messages puppeting bridge"
url="https://go.mau.fi/mautrix-gmessages/"
arch="all"
license="AGPL-3.0-or-later"
makedepends="go olm-dev sqlite-dev"
install="$pkgname.pre-install $pkgname.post-upgrade"
subpackages="$pkgname-openrc $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/mautrix/gmessages/archive/v$pkgver.tar.gz
	mautrix-gmessages.initd
	mautrix-gmessages.confd
	"
builddir="$srcdir/gmessages-$pkgver"
options="net"

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	export CGO_CFLAGS="$CFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"

	go build \
		-ldflags "-X main.Tag=$pkgver -X 'main.BuildTime=$(date -d @"$SOURCE_DATE_EPOCH" '+%b %_d %Y, %H:%M:%S')'" \
		./cmd/mautrix-gmessages

	./mautrix-gmessages -e
}

check() {
	go test -v ./...
}

package() {
	install -Dm755 mautrix-gmessages \
		-t "$pkgdir"/usr/bin/
	install -Dm644 config.yaml \
		-t "$pkgdir"/etc/mautrix-gmessages/

	install -Dm755 "$srcdir"/mautrix-gmessages.initd \
		"$pkgdir"/etc/init.d/mautrix-gmessages
	install -Dm644 "$srcdir"/mautrix-gmessages.confd \
		"$pkgdir"/etc/conf.d/mautrix-gmessages

	install -Dm 644 LICENSE "$pkgdir"/usr/share/licenses/"$pkgname"/LICENSE
}

sha512sums="
dee1be92d83afa04d3346563d93171f07e2c42657e0a72bba7d58e11c0092a9dfe272bd414897d48989356bb854d3ef1c26af58216d607483eaae22c21faf5f1  mautrix-gmessages-0.5.1.tar.gz
ed957641bdc1c56f7bea90db0fe4b845e5823323801033c710706116a9a06f98f2a808b8daa244f04b78676d595f12822040ff0b0863457a05222aac0c76750b  mautrix-gmessages.initd
3332b10948fc07845b3b9a775bbb01057d2e6c768e25b429a451dbfb668195eb9f2c1d6b435a944aa7e5618b6ae609fb16e471696176fe3ae0768dffec6618e5  mautrix-gmessages.confd
"
